import request from "@/utils/request"
import { AxiosPromise } from "axios"
import { CaptchaResult, LoginData, RegisterData, LoginResult } from "./types"

/**
 * 登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function loginApi(data: LoginData): AxiosPromise<LoginResult> {
  return request({
    url: "/admin/v1/common/login",
    method: "post",
    data,
  })
}
// 注册
export function registerApi(data: RegisterData): AxiosPromise<any> {
  return request({
    url: "/admin/v1/common/register",
    method: "post",
    data,
  })
}

/**
 * 注销API
 */
export function logoutApi() {
  return request({
    url: "/admin/v1/auth/logout",
    method: "delete",
  })
}

/**
 * 获取验证码
 */
export function getCaptchaApi(): AxiosPromise<CaptchaResult> {
  return request({
    url: "/api/v1/auth/captcha",
    method: "get",
  })
}
